package com.kkb.shopcenter.controller;

import com.kkb.shopcenter.api.RoleInfoService;
import com.kkb.shopcenter.api.UserInfoService;
import com.kkb.shopcenter.common.pojo.RoleInfo;
import com.kkb.shopcenter.common.pojo.UserInfo;
import com.kkb.shopcenter.common.utils.SecurityUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/auth")
public class AuthController {

    @Reference
    private UserInfoService userInfoService;

    @Reference
    private RoleInfoService roleInfoService;

    @GetMapping(value = "/info/{type}")
    public ResponseEntity<Object> getUserInfoRole(@PathVariable Integer type){
        UserInfo userInfo = userInfoService.findByUsername(SecurityUtils.getUserName());
        List<RoleInfo> roleInfos = roleInfoService.selectRolesByUserId(userInfo.getId());
        userInfo.setRoleList(roleInfos);
        return ResponseEntity.ok(userInfo);
    }
}
